/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import model.Base;

/**
 *
 * @author Ira
 */
public class UserView extends View {
	
	//<editor-fold defaultstate="collapsed" desc="nom des composants">
	public static final String MENU_CHANGE_PASS = "menu_change_pass";
	public static final String MENU_DECO = "menu_deco";
	public static final String MENU_QUIT = "menu_quit";
	public static final String MENU_ABOUT = "menu_about";
	//</editor-fold>
	
	
	private MainWindow mainWindow;
	private Base model;
	private SearchView searchView;
	private DocumentResultView resultView;
	private DocumentPropertiesView propertiesView;
	private BorrowDocumentView borrowView;
	
	public UserView(Base model, MainWindow mainWindow) {
		super();
		this.mainWindow = mainWindow;
		this.model = model;
		this.setMenu();
		this.searchView = new SearchView(model, false);
		this.resultView = new DocumentResultView(this);
		this.propertiesView = new DocumentPropertiesView(model, false, this);
		this.borrowView = new BorrowDocumentView(model);
		
		model.addObserver(this.resultView);
		model.addObserver(this.borrowView);
		this.resultView.addObserver(this.propertiesView);
		this.borrowView.addObserver(this.propertiesView);

		model.shareDataWithObs();
		
		GridBagConstraints constraint = new GridBagConstraints();
		constraint.anchor = GridBagConstraints.NORTH;
		
		// Vue des résultats
		constraint.gridx = 0;
		constraint.gridy = 0;
		constraint.weightx = 1.0;
		constraint.weighty = 1.0;
		constraint.fill = GridBagConstraints.BOTH;
		this.add(this.resultView, constraint);
		
		// Vue de recherche
		constraint.gridx = 1;
		constraint.weightx = 0.0;
		constraint.weighty = 0.0;
		this.add(this.searchView, constraint);
		
		// Vue des documents empruntés
		constraint.gridy = 1;
		this.add(this.borrowView, constraint);
		
		// Vue des attributs du doc selectionné
		constraint.gridx = 0;
		constraint.fill = GridBagConstraints.NONE;
		constraint.anchor = GridBagConstraints.CENTER;
		this.add(this.propertiesView, constraint);
		
	}
	
	private void setMenu() {
		JMenuBar menuBar;
		JMenu menu;
		JMenuItem item;
		
		menuBar = new JMenuBar();
		
		menu = new JMenu("Fichier");
		
		item  = new JMenuItem("Changer mon mot de passe");
		item.setName(UserView.MENU_CHANGE_PASS);
		//item.addActionListener(c);
		menu.add(item);
		
		item  = new JMenuItem("Déconnection");
		item.setName(UserView.MENU_DECO);
		//item.addActionListener(c);
		menu.add(item);
		
		item  = new JMenuItem("Quitter");
		item.setName(UserView.MENU_QUIT);
		//item.addActionListener(c);
		menu.add(item);
		
		menuBar.add(menu);
		
		menu = new JMenu("?");
		
		item  = new JMenuItem("A propos...");
		item.setName(UserView.MENU_ABOUT);
		//item.addActionListener(c);
		menu.add(item);
		
		menuBar.add(menu);
		
		this.mainWindow.setJMenuBar(menuBar);
	}
}
